<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Topic;
use App\Models\Category;
use App\Models\User;
use App\Models\Link;

class CategoriesController extends Controller
{
    public function show(Request $request, Category $category, Topic $topic, User $user, Link $link)
    {
        $order = $request->order;
        //读取分类ID关联的话题, 并按每20条分页
        $topics = $topic->withOrder($request->order)->where('category_id', $category->id)->paginate(20);
        //活跃用户列表
        $active_users = $user->getActiveUsers();
        //资源链接
        $links = $link->getAllCached();
        // 传参变量话题和分类到模板中
        return view('topics.index', compact('topics','category','order','active_users','links'));
    }
}
